<!DOCTYPE html>
<html>
<head lang="zh-cmn-Hans">
    <meta charset="UTF-8">
    <title>DSBridge Test</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=0.5,user-scalable=no"/>
    <!--require dsbridge init js-->
    <!--<script src="https://cdn.jsdelivr.net/npm/dsbridge/dist/dsbridge.js"> </script>-->
    <script src="./dsbridge.js"> </script>
</head>
<style>
    .btn {
        text-align: center;
        background: #d8d8d8;
        color: #222;
        padding: 20px;
        margin: 30px;
        font-size: 24px;
        border-radius: 4px;
        box-shadow: 4px 2px 10px #999;
    }

    .btn:active {
        opacity: .7;
        box-shadow: 4px 2px 10px #555;
    }

</style>
<body>
<h3>相关权限自己在应用设置中开启一下吧，框架只提供能力层，将权限模块剥离</h3>
<h2>-------native-------</h2>
<div class="btn" onclick="mac()">mac</div>
<div class="btn" onclick="getIMEI()">getIMEI</div>
<div class="btn" onclick="getIMSI()">getIMSI</div>
<div class="btn" onclick="packageName()">packageName</div>
<div class="btn" onclick="versionCode()">versionCode</div>
<div class="btn" onclick="versionName()">versionName</div>
<div class="btn" onclick="picture()">picture</div>
<div class="btn" onclick="camera()">camera</div>
<div class="btn" onclick="_location()">location</div>
<div class="btn" onclick="isUSBAttached()">isUSBAttached</div>
<div class="btn" onclick="restartApp()">restartApp</div>
<div class="btn" onclick="getAppCacheSize()">getAppCacheSize</div>
<div class="btn" onclick="clearAppCache()">clearAppCache</div>
<div class="btn" onclick="saveLocalData()">saveLocalData</div>
<div class="btn" onclick="getLocalData()">getLocalData</div>
<div class="btn" onclick="isGPSOpen()">isGPSOpen</div>
<div class="btn" onclick="openGPS()">openOrCloseGPS</div>
<div class="btn" onclick="callPhone()">callPhone</div>
<div class="btn" onclick="sendSMS()">sendSMS</div>
<div class="btn" onclick="getBSInfo()">getBSInfo</div>

<h2>-------common-------</h2>
<div class="btn" onclick="openBrowser()">openBrowser</div>
<div class="btn" onclick="download_apk()">download_apk</div>
<div class="btn" onclick="showToast()">showToast</div>
<div class="btn" onclick="showSnackBar()">showSnackBar</div>
<div class="btn" onclick="activityFinish()">activityFinish</div>
<div class="btn" onclick="isInstall()">isInstall</div>

<h2>-------custom-------</h2>
<div class="btn" onclick="customAPI()">customAPI</div>


<h2>-------debug-------</h2>
<div class="btn" onclick="Test1()">Test1</div>
<div class="btn" onclick="Test2()">Test2</div>
<div class="btn" onclick="permission()">permission</div>

<script>

    ////////////////// native //////////////////
    function isGPSOpen() {
        console.log(dsBridge.call("native.isGPSOpen"));
    }

    function getBSInfo() {
        console.log(dsBridge.call("native.getBSInfo"));
    }

    function openGPS() {
        dsBridge.call("native.openOrCloseGPS");
    }

    function callPhone() {
        dsBridge.call("native.callPhone", '1383838338');
    }

    function sendSMS() {
        dsBridge.call("native.sendSMS", '{"pn":"1383838338","message":"im message content.........."}');
    }

    function mac() {
        console.log(dsBridge.call("native.getMac"));
    }

    function saveLocalData() {
        dsBridge.call("native.saveLocalData", '{"key":"my_key","value":123}');
    }

    function getLocalData() {
        console.log(dsBridge.call("native.getLocalData",'{"key":"my_key","default_value":1}'));
    }

    function getAppCacheSize() {
        console.log(dsBridge.call("native.getAppCacheSize"));
    }

    function clearAppCache() {
        dsBridge.call("native.clearAppCache")
    }

    function restartApp() {
        console.log(dsBridge.call("native.restartApp"));
    }

    function isUSBAttached() {
        console.log(dsBridge.call("native.isUSBAttached"));
    }

    function _location() {
        console.log(dsBridge.call("native.getLocation"));
    }

    function picture() {
        dsBridge.call("native.openGallery", function(value) {
            console.log(value)
        });
    }

    function camera() {
        dsBridge.call("native.openCamera", function(value) {
            console.log(value)
        });
    }

    function getIMEI() {
        console.log(dsBridge.call("native.getIMEI"));
    }

    function getIMSI() {
        console.log(dsBridge.call("native.getIMSI"));
    }

    function versionCode() {
        console.log(dsBridge.call("native.getVersionCode"));
    }

    function packageName() {
        console.log(dsBridge.call("native.getPackageName"));
    }

    function versionName() {
        console.log(dsBridge.call("native.getVersionName"));
    }

    ////////////////// common //////////////////
    function openBrowser() {
        dsBridge.call("common.openBrowser", 'http://192.168.0.1');
    }

    function activityFinish() {
        dsBridge.call("common.activityFinish");
    }

    function isInstall() {
        console.log(dsBridge.call("common.isInstall", 'com.clouds.xk'));
    }

    function showToast() {
        dsBridge.call("common.showToast", 'false');
    }

    function showSnackBar() {
        dsBridge.call("common.showSnackBar", '{"type":0,"message":"im message content...","action":"确定"}', function(){
            console.log("completed...");
        });
    }
    function download_apk() {
        dsBridge.call("common.downloadApk", 'http://down-ww2.newasp.net/soft/7/90/com.generdal.rhgawd.aownd_eec2a470.apk');
        //dsBridge.call("common.downloadApk", 'https://qd.myapp.com/myapp/qqteam/AndroidQQ/mobileqq_android.apk');
    }

    ////////////////// navigation //////////////////
    function getNavigationCategory() {
        console.log(dsBridge.call("navigation.getNavigationCategory"))
    }

    function navigationTo() {
        dsBridge.call("navigation.navigationTo", '{"type":2, "latitude":39.5209922936, "longitude":112.0825195313, "aimAddress":"山西省朔州市平鲁区304省道"}')
    }

    ////////////////// custom //////////////////
    function customAPI() {
        dsBridge.call("test.custom")
    }
    ////////////////// debug //////////////////
    function Test1() {
        dsBridge.call("debug.call", obj);
    }

    function Test2() {
        console.log(dsBridge.call("debug.back", obj));
    }
    
    ////////////////// listener //////////////////
    dsBridge.register('callback', function (value) {
        console.log(value);
        //{"key":"android_event_on_back","value":true}
        var params = JSON.parse(value);
        if(params.key === "key_event_on_back" && params.value === true) {
            activityFinish();
        }

    })
    
</script>
</body>
</html>
